import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';
import store from './store/store.js';
import router from './router/index.js';
import axios from 'axios';
import { Message } from 'element-ui';

Vue.config.productionTip = false;

Vue.use(ElementUI);
// //http://grjj.secosoft.cn/测试环境
//  //https://wx.mdcare.com.cn/正式环境
Vue.prototype.showTestFeatures = process.env.VUE_APP_SHOW_TEST_FEATURES === 'true';

Vue.prototype.base_url = process.env.VUE_APP_API_BASE;
console.log(`当前环境: ${process.env.VUE_APP_ENV}`);
//阿里OSS对象储存域名
Vue.prototype.$oss_url = 'https://djb.oss-cn-shanghai.aliyuncs.com/';
//阿里OSSaccessKeyId
Vue.prototype.$accessKeyId = 'LTAI5tQdJkE62W1Z5jy8SAa4';
Vue.prototype.$accessKeySecret = 'qD68YV45XyXNuPQxOaPPRbKsCsvdhu';
Vue.prototype.$bucket = 'djb';
Vue.prototype.$region = 'oss-cn-shanghai';

//封装公共AJAX函数
Vue.prototype.ajaxs = (url, obj, headers = { 'Content-Type': '' }) => {
    var data = obj.data ? obj.data : {};
    axios({
        method: 'POST',
        url: '/seller/' + url,
        timeout: 60000, // 或者者更大的毫秒数值
        data: data,
        headers:
            headers['Content-Type'] == ''
                ? {
                      'Content-Type': 'application/json',
                      'x-requested-with': 'XMLHttpRequest',
                  }
                : headers,
    })
        .then(res => {
            res = res.data;
            if (res.code == 4) {
                store.commit('loginOut');
                router.push({
                    path: '/index/login/login',
                });
            } else {
                obj.success(res);
            }
        })
        .catch(err => {
            console.log(err);
            Message.error(err);
        })
        .catch(e => {
            Message.error(e);
        });
};

//gf独立
Vue.prototype.ajaxsC = (url, obj, headers = { 'Content-Type': '' }) => {
    var data = obj.data ? obj.data : {};
    axios({
        method: 'POST',
        url: url,
        timeout: 60000, // 或者者更大的毫秒数值
        data: data,
        headers:
            headers['Content-Type'] == ''
                ? {
                      'Content-Type': 'application/json',
                      'x-requested-with': 'XMLHttpRequest',
                  }
                : headers,
    })
        .then(res => {
            res = res.data;
            obj.success(res);
        })
        .catch(err => {
            Message.error(err);
        })
        .catch(e => {
            Message.error(e);
        });
};

//封装网页弹窗
Vue.prototype.toast = (code, msg, func = () => {}) => {
    if (code == 1) {
        Message.success(msg);
    }
    if (code == 0) {
        Message.warning(msg);
    }
    setTimeout(func, 1000);
};

new Vue({
    store,
    router,
    render: h => h(App),
}).$mount('#app');
